Opencv学习笔记 均方误差(MSE)、结构相似度指数(SSIM) |
您所在的位置:网站首页 › opencv ssim函数 › Opencv学习笔记 均方误差(MSE)、结构相似度指数(SSIM) |
均方误差(mean-square error, MSE)是反映估计量与被估计量之间差异程度的一种度量。设t是根据子样确定的总体参数θ的一个估计量,(θ-t)2的数学期望,称为估计量t的均方误差。它等于σ2+b2,其中σ2与b分别是t的方差与偏倚。
SSIM(Structural SIMilarity),结构相似性,是一种衡量两幅图像相似度的指标。该指标首先由德州大学奥斯丁分校的图像和视频工程实验室(Laboratory for Image and Video Engineering)提出。SSIM使用的两张图像中,一张为未经压缩的无失真图像,另一张为失真后的图像。 参考代码: #import skimage.measure from skimage.metrics import structural_similarity as ssim # from skimage import measure import matplotlib.pyplot as plt import numpy as np import cv2 def mse(imageA, imageB): # the 'Mean Squared Error' between the two images is the # sum of the squared difference between the two images; # NOTE: the two images must have the same dimension err = np.sum((imageA.astype("float") - imageB.astype("float")) ** 2) err /= float(imageA.shape[0] * imageA.shape[1]) # return the MSE, the lower the error, the more "similar" # the two images are return err def compare_images(imageA, imageB, title): # compute the mean squared error and structural similarity # index for the images m = mse(imageA, imageB) s = ssim(imageA, imageB) # setup the figure fig = plt.figure(title) plt.suptitle("MSE: %.2f, SSIM: %.2f" % (m, s)) # show first image ax = fig.add_subplot(1, 2, 1) plt.imshow(imageA, cmap=plt.cm.gray) plt.axis("off") # show the second image ax = fig.add_subplot(1, 2, 2) plt.imshow(imageB, cmap=plt.cm.gray) plt.axis("off") # show the images plt.show() # load the images -- the original, the original + contrast, # and the original + photoshop original = cv2.imread("C:/Users/Desktop/111.png") contrast = cv2.imread("C:/Users/Desktop/222.png") shopped = cv2.imread("C:/Users/Desktop/333.png") # convert the images to grayscale original = cv2.cvtColor(original, cv2.COLOR_BGR2GRAY) contrast = cv2.cvtColor(contrast, cv2.COLOR_BGR2GRAY) shopped = cv2.cvtColor(shopped, cv2.COLOR_BGR2GRAY) # initialize the figure fig = plt.figure("Images") images = ("Original", original), ("Contrast", contrast), ("Photoshopped", shopped) # loop over the images for (i, (name, image)) in enumerate(images): # show the image ax = fig.add_subplot(1, 3, i + 1) ax.set_title(name) plt.imshow(image, cmap = plt.cm.gray) plt.axis("off") # show the figure plt.show() # compare the images compare_images(original, original, "Original vs. Original") compare_images(original, contrast, "Original vs. Contrast") compare_images(original, shopped, "Original vs. Photoshopped")
遇到import structural_similarity错误: 旧:from skimage.measure import structural_similarity as ssim 新:from skimage.metrics import structural_similarity as ssim 参考文章: https://www.cnblogs.com/darkchii/p/12679103.html https://blog.csdn.net/weixin_33937778/article/details/88667697 https://blog.csdn.net/chaipp0607/article/details/70160307 |
今日新闻 |
点击排行 |
|
推荐新闻 |
图片新闻 |
|
专题文章 |
CopyRight 2018-2019 实验室设备网 版权所有 win10的实时保护怎么永久关闭 |